package com.att.config;

import com.android.ddmlib.IShellOutputReceiver;

public class GetEventCmdOutputReceiver implements IShellOutputReceiver {

    private ReceiverCallback callback;
    private int eventNum;
    public void setCallback(ReceiverCallback callback) {
        this.callback = callback;
    }
    
    public void setEventNum(int eventNum) {
        this.eventNum = eventNum;
    }
    
    @Override
    public void addOutput(byte[] arg0, int arg1, int arg2) {
        String result = new String(arg0, arg1, arg2);
        System.out.println(result);
        String[] arr = result.trim().split("\r\n");
        final StringBuilder sb = new StringBuilder();
        for (String item : arr) {
            String[] temp = item.split(" ");
            int a = Integer.valueOf(temp[0], 16);//temp[0];//Integer.valueOf(temp[0], 16);
            int b = Integer.valueOf(temp[1], 16);//temp[1];     //Integer.valueOf(temp[1], 16);
            int c = Integer.valueOf(temp[2], 16);
//            System.out.println(a + " " + b + " " + c);
            sb.append("sendevent dev/input/event" + eventNum + " " + a + " " + b + " " + c + "\r\n");
        }
        if (callback != null) {
            callback.doPerform(sb.toString());
        }
    }

    @Override
    public void flush() {
    }

    @Override
    public boolean isCancelled() {
        return false;
    }
    
}
